package dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import pojo.Message;

public interface MessageDao {
	
	//查询用户的消息;
	@Select(value="select * from message where ruser_id=#{userId} order by message_date desc")
	@Results({
		@Result(column="message_id",property="messageId",id=true),
		@Result(column="message_content",property="messageContent"),
		@Result(column="message_date",property="messageDate" ),
		@Result(column="ruser_id",property="ruserId"),
		@Result(column="suser_id",property="suserId")
	})
	public List<Message> selectByUser(Integer userId);
	
	//查询用户当天的消息
	@Select(value="select * from message where ruser_id=#{userId} and message_date=#{date}")
	@Results({
		@Result(column="message_id",property="messageId",id=true),
		@Result(column="message_content",property="messageContent"),
		@Result(column="message_date",property="messageDate" ),
		@Result(column="ruser_id",property="ruserId"),
		@Result(column="suser_id",property="suserId")
	})
	public List<Message> selectByDate(@Param("Integer")Integer userId,@Param("date")String date);
	
	//查询用户当天消息的Id
	@Select(value="select message_id from message where ruser_id=#{userId} and message_date")
	@Results({
		@Result(column="message_id",property="messageId",id=true),
	})
	public List<Integer> selectMessageId(@Param("userId")Integer userId,@Param("date")String date);
	
	//删除用户当天/全部的消息/根据messageId删除message/删除特定的消息
	public int deleteById(Integer messageId);
	
	//查询用户全部消息的ID
	@Select(value="select * from message where ruser_id=#{userId}")
	@Results({
		@Result(column="message_id",property="messageId",id=true),
		@Result(column="message_content",property="messageContent"),
		@Result(column="message_date",property="messageDate" ),
		@Result(column="ruser_id",property="ruserId"),
		@Result(column="suser_id",property="suserId")
	})
	public List<Integer> selectAllMessageId(Integer userId);
	
	//查询用户未读消息
	@Select(value="select * from message where ruser_id=#{userId} and readornot=#{read}")
	@Results({
		@Result(column="message_id",property="messageId",id=true),
		@Result(column="message_content",property="messageContent"),
		@Result(column="message_date",property="messageDate" ),
		@Result(column="ruser_id",property="ruserId"),
		@Result(column="suser_id",property="suserId")
	})
	public List<Message> selectNotRead(@Param("userId")Integer userId,@Param("read")Integer read);

	//查询用户已读消息
		@Select(value="select * from message where ruser_id=#{userId} and readornot=#{read}")
		@Results({
			@Result(column="message_id",property="messageId",id=true),
			@Result(column="message_content",property="messageContent"),
			@Result(column="message_date",property="messageDate" ),
			@Result(column="ruser_id",property="ruserId"),
			@Result(column="suser_id",property="suserId")
		})
	public List<Message> selectRead(@Param("userId")Integer userId,@Param("read")Integer read);
	
}
